package com.zhen.aikan.controller;

import com.zhen.aikan.entity.History;
import com.zhen.aikan.service.IHistoryService;
import com.zhen.aikan.vo.HistoryVo;
import com.zhen.aikan.vo.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lijiazhen
 * @since 2023-09-11
 */
@RestController
@RequestMapping("/api/history")
public class HistoryController {
    @Autowired
    private IHistoryService historyService;
    @ApiOperation("新增历史记录")
    @GetMapping("/addHistory")
    public Result addHistory(History history){
        boolean success = historyService.addHistory(history);
        return Result.ok(success?1:0);
    }

    @ApiOperation("根据用户账户获取该用户的历史观看记录")
    @GetMapping("/getHistory")
    public Result getHistoryByUserId(String userId){
        List<HistoryVo> histories = historyService.getHistoryByUserId(userId);
        return Result.ok(histories);
    }

}
